
$(function () {
    //获取文章类型
    $.ajax({
        method: 'GET',
        url: BigNew.category_list,
        data: {},
        success: (backData) => {
            //模板引擎渲染
            $('[name="categoryId"]').html(template('category_list', { res: backData }));
        }
    })


    $(".btn-release").click(function (e) {
        //阻止默认提交事件
        e.preventDefault();
        articleRequest("已发布");
    })
    $(".btn-draft").click(function (e) {
        //阻止默认提交事件
        e.preventDefault();
        articleRequest("草稿");
    })


    function articleRequest(state) {

        let fd = new FormData($("#form").get(0));
        fd.append("state", state);

        //tinyMCE获取内容的方法
        fd.append("content", tinyMCE.activeEditor.getContent());
        $.ajax({
            method: 'POST',
            url: BigNew.article_publish,
            contentType: false,
            processData: false,
            data: fd,
            success: (res) => {
                console.log(res);
                alert(res.msg);
                window.history.back();
            },
            error: (res) => {
                console.log(res);
                alert(res.data)
            }
        })
    }
})

